/*
 * @Date: 2021-12-06 23:50:59
 * @LastEditors: xiaolan
 * @LastEditTime: 2021-12-07 17:23:37
 * @FilePath: \pms\web\keshihua\js\index.js
 */
;(function () {
  let user_role = sessionStorage.getItem('user_role')
  let user_id = sessionStorage.getItem('user_id')
  let notice_list = []
  let meet_list = []
  let process_list = []
  let document_list = []
  let projectID_list = []
  let data_list = []

  $.ajax({
    async: false,
    url: '../project/notice',
    type: 'POST',
    data: {
      action: 'query',
      role: user_role,
      id: user_id,
    },
    success(result) {
      notice_list = JSON.parse(result).list
    },
  })

  let str = ''
  for (let i of notice_list) {
    str += `<ul class="ul_con">
								<li>${i.id}</li>
								<li>${i.publisherName}1</li>
								<li>${i.time}</li>
								<li>${i.title}</li>
								<li>${i.content}</li>
						</ul>`
  }
  document.querySelector('#notice').innerHTML = str

  $.ajax({
    async: false,
    url: '../project/meet',
    type: 'POST',
    data: {
      action: 'query',
      role: user_role,
      id: user_id,
    },
    success(result) {
      meet_list = JSON.parse(result).meetings
    },
  })
  str = ''
  for (let i of meet_list) {
    str += `<ul class="ul_con">
								<li>${i.id}</li>
								<li>${i.publisherName}1</li>
								<li>${i.deliverTime}</li>
								<li>${i.title}</li>
								<li>${i.content}</li>
								<li>${i.meetTime}</li>
						</ul>`
  }
  document.querySelector('#meet').innerHTML = str

  if (user_role === '组员') {
    $.ajax({
      async: false,
      url: '../project/action1',
      type: 'POST',
      data: {
        action: 'get_task_info',
        user_role,
        user_id,
      },
      success(result) {
        process_list = JSON.parse(result).aaData
      },
    })
    for (let i of process_list) {
      projectID_list.push(i.content)
      data_list.push(i.progress)
    }
  }

  if (user_role === '管理员' || user_role==='组长') {
    $.ajax({
      async: false,
      url: '../project/action',
      type: 'POST',
      data: {
        action: 'get_project_info',
        user_role,
        user_id,
      },
      success(result) {
        process_list = JSON.parse(result).project_list
      },
    })
    for (let i of process_list) {
      projectID_list.push(i.project_name)
      data_list.push(i.progress)
    }
  }

  var dataAxis = projectID_list
  var data = data_list
  var yMax = 100
  var dataShadow = []

 

  option = {
    title: {
      text: '',
      subtext: '',
    },
		tooltip:{
			trigger:'axis',
			axisPointer:{
				type:'shadow'
			}
		},

    grid: {
      x: 40,
      y: 40,
      x2: 20,
      y2: 20,
    },

    xAxis: {
      data: dataAxis,
      axisLabel: {
        /*inside: true,*/
        interval: 0,
        textStyle: {
          color: '#fff',
          fontSize: 12,
        },
      },
      axisTick: {
        show: false,
      },
      axisLine: {
        show: true,
        symbol: ['none', 'arrow'],
        symbolOffset: 12,
        lineStyle: {
          color: '#fff',
        },
      },
      z: 10,
    },
    yAxis: {
      type: 'value',
      name: '单位:%',
      axisLine: {
        show: true,
        symbol: ['none', 'arrow'],
        symbolOffset: 12,
        lineStyle: {
          color: '#fff',
        },
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        textStyle: {
          color: '#fff',
          fontSize: 12,
        },
      },
			max:100
    },

    dataZoom: [
      {
        type: 'inside',
      },
    ],

    series: [
      {
        // For shadow
        type: 'bar',
        itemStyle: {
          color: 'rgba(0,0,0,0.05)',
        },
        barGap: '-100%',
        barCategoryGap: '40%',
        data: dataShadow,
        animation: false,
      },
      {
        type: 'bar',
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: '#0efdff',
            },
            {
              offset: 0.5,
              color: '#188df0',
            },
            {
              offset: 1,
              color: '#188df0',
            },
          ]),
        },
        emphasis: {
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: '#2378f7',
              },
              {
                offset: 0.7,
                color: '#2378f7',
              },
              {
                offset: 1,
                color: '#0efdff',
              },
            ]),
          },
        },
        data: data,
      },
    ],
  }
  //获取dom容器
  var myChart = echarts.init(document.getElementById('chartmain'))
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option)

  var module = '../project_documents'
  var sub = 'file'

  $.ajax({
    async: false,
    url:
      module + '_' + sub + '_servlet_action?action=get_file_information_record',
    type: 'POST',
    success(result) {
      document_list = result.aaData
    },
  })

  document.getElementById('total_doc').innerHTML = document_list.length
  document.getElementById('total_notice').innerHTML = notice_list.length
  document.getElementById('total_meet').innerHTML = meet_list.length
  document.getElementById('total_project').innerHTML = process_list.length
})()
